﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

public class MainCamera : MonoBehaviour {
    private Transform _camera_target;

    // Use this for initialization
    void Start () {

        // 相机绑定在目标物体上。
        _camera_target = transform.parent;
    }

    // LateUpdate is called once per frame
    void LateUpdate () {
        if (Input.GetMouseButton(1))
        {
            // 围绕物体转动相机
            float h = -10 * Input.GetAxis("Mouse X");
            float v = 10 * Input.GetAxis("Mouse Y");
            transform.RotateAround(_camera_target.position, transform.up, h);
            transform.RotateAround(_camera_target.position, transform.right, v);
        }

        // 滚轮控制距离物体远近。
        var delta = Input.GetAxis("Mouse ScrollWheel") * 2;
        transform.position -= transform.forward * delta;
    }

}
